package com.ld.wms.business.material.controller;


import com.ld.wms.business.material.model.MaterialExampleModel;
import com.ld.wms.business.material.service.MaterialExampleService;
import com.ld.wms.business.material.vo.req.MaterialExampleReqVo;
import com.ld.wms.business.material.vo.resp.FieldInfoRespVo;
import com.ld.wms.business.material.vo.resp.MaterialExampleLikeSearchRespVo;
import com.ld.wms.business.material.vo.resp.MaterialExampleRespVo;
import com.ld.wms.common.ResultResponse;
import com.ld.wms.common.vo.GenerateListVo;
import com.ld.wms.common.vo.GeneratePageListVo;
import com.ld.wms.common.vo.PrimaryKeyReqVo;
import com.ld.wms.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 物料实例表，具体的物料想信息 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2025-02-24
 */
@Slf4j
@Tag(name = "物料/试剂实例相关接口")
@RestController
public class MaterialExampleController {

    @Autowired
    private MaterialExampleService materialExampleService;

    @GetMapping("/api/wms/materialExample/getPageList")
    @Operation(summary = "物料管理-物料列表(查询所有size传9999)")
    public ResultResponse<GeneratePageListVo<MaterialExampleRespVo>> getPageList(
            @Parameter(description = "物料试剂类型") @RequestParam(required = false) Long materialTypeId,
            @Parameter(description = "CAS码") @RequestParam(required = false) String casCode,
            @Parameter(description = "物料名称") @RequestParam(required = false) String name,
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer size
    ) {

        GeneratePageListVo<MaterialExampleRespVo> allList = materialExampleService.getPageByCondition(materialTypeId, casCode, name, current, size);
        return ResultResponse.success(allList);
    }

    @GetMapping("/api/wms/materialExample/getInventoryInsufficientPageList")
    @Operation(summary = "首页-库存不足列表")
    public ResultResponse<GeneratePageListVo<MaterialExampleRespVo>> getInventoryInsufficientPageList(
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer size
    ) {
        GeneratePageListVo<MaterialExampleRespVo> allList = materialExampleService.getInventoryInsufficientPageList(current, size);
        return ResultResponse.success(allList);
    }

    @GetMapping("/api/wms/materialExample/getMaterialExampleLikeSearch")
    @Operation(summary = "物料管理-搜索框提示用")
    public ResultResponse<GenerateListVo<MaterialExampleLikeSearchRespVo>> getMaterialExampleLikeSearch(
            @Parameter(description = "物料名称") @RequestParam(required = false) String name
    ) {
        GenerateListVo<MaterialExampleLikeSearchRespVo> allList = materialExampleService.getMaterialExampleLikeSearch(name);
        return ResultResponse.success(allList);
    }


    @GetMapping("/api/wms/materialExample/getById")
    @Operation(summary = "详情")
    public ResultResponse<MaterialExampleRespVo> getById(
            @RequestParam Long id
    ) {
        MaterialExampleRespVo byId = materialExampleService.getDetails(id);
        return ResultResponse.success(byId);
    }

    @PostMapping("/api/wms/materialExample/add")
    @Operation(summary = "添加")
    public ResultResponse<ResultResponseEnum> add(
            @RequestBody MaterialExampleReqVo reqVo
    ) {
        materialExampleService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/wms/materialExample/update")
    @Operation(summary = "修改")
    public ResultResponse<ResultResponseEnum> update(
            @RequestBody MaterialExampleReqVo reqVo
    ) {
        materialExampleService.updateById(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/wms/materialExample/deleteById")
    @Operation(summary = "删除")
    public ResultResponse<ResultResponseEnum> deleteById(
            @RequestBody PrimaryKeyReqVo reqVo
    ) {
        materialExampleService.deleteById(reqVo.getId());
        return ResultResponse.success();
    }
}

